package com.graduationdesign.zengyan.graduationdesignapp.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;

import java.util.List;

/**
 * Created by ZengYan on 2018/4/24.
 *
 * @desc :
 */
public class PhoneUtils {

    public static void call(Activity activity, String phone) {
        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
        if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        activity.startActivity(intent);
    }

    public static void message(Activity activity ,List<String> phones) {
        Uri uri2 = Uri.parse("smsto:" + phones.get(0));
        Intent intentMessage = new Intent(Intent.ACTION_VIEW,uri2);
        activity.startActivity(intentMessage);
    }
}
